package com.ruoyi.web.controller.easywenku;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.easywenku.entity.RegistrationInfo;
import com.ruoyi.easywenku.service.RegistrationInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 报名信息Controller
 *
 * @author ruoyi
 * @date 2021-06-18
 */
@Controller
@RequestMapping("/easywenku/registrationInfo")
public class RegistrationInfoController extends BaseController
{
    private String prefix = "easywenku/registrationInfo";

    @Autowired
    private RegistrationInfoService registrationInfoService;

    @RequiresPermissions("easywenku:registrationInfo:view")
    @GetMapping()
    public String registrationInfo()
    {
        return prefix + "/registrationInfo";
    }

    /**
     * 查询报名信息列表
     */
    @RequiresPermissions("easywenku:registrationInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RegistrationInfo registrationInfo)
    {
        startPage();
        List<RegistrationInfo> list = registrationInfoService.list(new QueryWrapper<>(registrationInfo));
        return getDataTable(list);
    }

    /**
     * 导出报名信息列表
     */
    @RequiresPermissions("easywenku:registrationInfo:export")
    @Log(title = "报名信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RegistrationInfo registrationInfo)
    {
        List<RegistrationInfo> list = registrationInfoService.list(new QueryWrapper<>(registrationInfo));
        ExcelUtil<RegistrationInfo> util = new ExcelUtil<RegistrationInfo>(RegistrationInfo.class);
        return util.exportExcel(list, "registrationInfo");
    }

    /**
     * 新增报名信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存报名信息
     */
    @RequiresPermissions("easywenku:registrationInfo:add")
    @Log(title = "报名信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RegistrationInfo registrationInfo)
    {
        return toAjax(registrationInfoService.save(registrationInfo));
    }

    /**
     * 修改报名信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        RegistrationInfo registrationInfo = registrationInfoService.getById(id);
        mmap.put("registrationInfo", registrationInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存报名信息
     */
    @RequiresPermissions("easywenku:registrationInfo:edit")
    @Log(title = "报名信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RegistrationInfo registrationInfo)
    {
        return toAjax(registrationInfoService.updateById(registrationInfo));
    }

    /**
     * 删除报名信息
     */
    @RequiresPermissions("easywenku:registrationInfo:remove")
    @Log(title = "报名信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        List<String> strings = Arrays.asList(ids.split(","));

        List<Long> collect = strings.stream().map(Long::parseLong).collect(Collectors.toList());
        boolean b = registrationInfoService.removeByIds(collect);

        return toAjax(b);
    }
}
